export const emojiList = [
  {
    content: "😀",
    rule: "[1]",
  },
  {
    content: "🤮",
    rule: "[2]",
  },
  {
    content: "🥶",
    rule: "[3]",
  },
  {
    content: "🤬",
    rule: "[4]",
  },
  {
    content: "💩",
    rule: "[5]",
  },
  {
    content: "🤡",
    rule: "[6]",
  },
  {
    content: "🙈",
    rule: "[7]",
  },
  {
    content: "💟",
    rule: "[8]",
  },
  {
    content: "💣",
    rule: "[9]",
  },
];

export const stringToEmoji = (str) => {
  return str.replace(/(\[\d+\])/g, ($) => {
    console.log($, "========$");
    const item = emojiList.find((v) => v.rule === $);
    if (item) return item.content;
    return $;
  });
};

export const emojiToString = (str) => {
  const emoji = emojiList.map((v) => v.content).join("|");

  const reg = new RegExp(emoji, "g");
  return str.replace(reg, ($) => {
    const item = emojiList.find((v) => v.content === $);
    if (item) return item.rule;
    return $;
  });
};
